﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.IDAL;
using KPIS.GERP.GFMS.DALFactory;

// test only
using KPIS.GERP.GFMS.DAL;

namespace KPIS.GERP.GFMS.BLL
{
    public class B_FIM_Payments : IBLL_FIM_Payments
    {
        Common common = new Common();
        private static readonly IDAL_FIM_Payments dal = DataAccess.Create_FIM_Payments();
        //D_FIM_MAS_Receives r = new D_FIM_MAS_Receives();

        public B_FIM_Payments()
        {

        }

        public IList<M_FIM_Payments> GetFull(string bgm_source_seq
            , string bgm_year, string work_area_seq, string event_seq, string direct_pay)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            Nullable<int> nwork_area_seq = common.ConvertNullInt(work_area_seq);
            Nullable<int> nevent_seq = common.ConvertNullInt(event_seq);
            return dal.GetFull(nbgm_source_seq, nbgm_year, nwork_area_seq, nevent_seq, direct_pay);
        }

        public IList<M_FIM_Payments> GetList(string bgm_source_seq
            , string bgm_year, string work_area_seq, string event_seq)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            Nullable<int> nwork_area_seq = common.ConvertNullInt(work_area_seq);
            Nullable<int> nevent_seq = common.ConvertNullInt(event_seq);
            return dal.GetList(nbgm_source_seq, nbgm_year, nwork_area_seq, nevent_seq);
        }

        public double GetVatBuySale(int month, int year, int? bgm_source_seq, int? pay_seq)
        {
            return dal.GetVatBuySale(month, year, bgm_source_seq, pay_seq);
        }

        public DataTable GetVatBuy(int month, int year, int? bgm_source_seq, int? pay_seq)
        {
            return dal.GetVatBuy(month, year, bgm_source_seq, pay_seq);
        }

        public DataTable GetVatSale(int month, int year, int? bgm_source_seq, int? pay_seq)
        {
            return dal.GetVatSale(month, year, bgm_source_seq, pay_seq);
        }

        public List<M_FIM_Vat> GetVatFull(string bgm_source_seq, string bgm_year)
        {
            return dal.GetVatFull(bgm_source_seq, bgm_year);
        }
        public M_FIM_Vat GetVatInfo(string vat_seq)
        {
            return dal.GetVatInfo(vat_seq);
        }

        public M_FIM_Vat GetVatInfoFromPaySeq(string pay_seq)
        {
            return dal.GetVatInfoFromPaySeq(pay_seq);
        }

        public List<M_FIM_Payments> GetIncludeVatPayment(int month, int year, int? bgm_source_seq, int? vat_seq)
        {
            return dal.GetIncludeVatPayment(month, year, bgm_source_seq, vat_seq);
        }
        public List<M_FIM_MoneyReturnDtls> GetIncludeVatReturnDtls(int month, int year, int? bgm_source_seq, int? vat_seq)
        {
            return dal.GetIncludeVatReturnDtls(month, year, bgm_source_seq, vat_seq);
        }
        public List<M_FIM_Receives> GetIncludeVatReceive(int month, int year, int? bgm_source_seq, int? vat_seq)
        {
            return dal.GetIncludeVatReceive(month, year, bgm_source_seq, vat_seq);
        }
        public string InsertVat(M_FIM_Vat info)
        {
            return dal.InsertVat(info);
        }
        public void UpdateVat(M_FIM_Vat info)
        {
            dal.UpdateVat(info);
        }
        public void DeleteVat(string vat_seq, int emp_seq)
        {
            dal.DeleteVat(vat_seq, emp_seq);
        }
        public string InsertVatDtls(M_FIM_Vat_Dtls info)
        {
            return dal.InsertVatDtls(info);
        }
        public void UpdateVatDtls(M_FIM_Vat_Dtls info)
        {
            dal.UpdateVatDtls(info);
        }
        public void DeleteVatDtls(string vat_seq)
        {
            dal.DeleteVatDtls(vat_seq);
        }

        public double GetPrevVatBuySale(int month, int year)
        {
            return dal.GetPrevVatBuySale(month, year);
        }

        public M_FIM_Payments GetInfo(string seq)
        {
            int nSeq;
 
            if (seq == null)
                return null;

            if (common.IsNumeric(seq))
            {
                nSeq = int.Parse(seq);
                return dal.GetInfo(nSeq);
            }
            else
            {
                return null;
            }
        }

        public M_FIM_Payments GetInfoFromMoneyReqSeq(string money_req_seq)
        {
            int nSeq;

            if (money_req_seq == null)
                return null;

            if (common.IsNumeric(money_req_seq))
            {
                nSeq = int.Parse(money_req_seq);
                return dal.GetInfoFromMoneyReqSeq(nSeq);
            }
            else
            {
                return null;
            }
        }

        public IList<M_FIM_Payments> GetListFromPetition(string petition_seq)
        {
            int nSeq;

            if (petition_seq == null)
                return null;

            if (common.IsNumeric(petition_seq))
            {
                nSeq = int.Parse(petition_seq);
                return dal.GetListFromPetition(nSeq);
            }
            else
            {
                return null;
            }
        }

        public IList<M_FIM_Payments> GetNotPayTax(int? TaxPaySeq, string strBgmSourceSeq, string strBgmYear, string strContactType)
        {
            return dal.GetNotPayTax(TaxPaySeq, strBgmSourceSeq, strBgmYear, strContactType);
        }

        public void UpdateTaxPaySeq(int pay_seq, int? tax_pay_seq, int update_by)
        {
            dal.UpdateTaxPaySeq(pay_seq, tax_pay_seq, update_by);
        }

        public string Insert(M_FIM_Payments info)
        {
            try
            {
                return dal.Insert(info);
            }
            catch
            {
                throw;
            }
        }

        public void Update(M_FIM_Payments info)
        {
            try
            {
                dal.Update(info);
            }
            catch
            {
                throw;
            }
        }

        public void Delete(M_FIM_Payments info)
        {
            try
            {
                dal.Delete(info);
            }
            catch
            {
                throw;
            }
        }

        public void ChangeStatus(M_FIM_Payments info)
        {
            try
            {
                dal.ChangeStatus(info);
            }
            catch
            {
                throw;
            }
        }
        public bool UpdatePayinpack(IList<M_FIM_Payments> lst) {
            try
            {
                return dal.UpdatePayinpack(lst);
            }
            catch
            {
                throw;
            }
        }

        public void UpdateReceipt(M_FIM_Payments info)
        {
            try
            {
                dal.UpdateReceipt(info);
            }
            catch
            {
                throw;
            }
        }

        public DataTable Report_SumUpPayment(string date)
        {
            Nullable<DateTime> ddate = common.ConvertNullDateTime(date);
            return dal.Report_SumUpPayment(ddate);
        }

        public IList<M_BGM_MAS_Source> GetBgmSource()
        {
            return dal.GetBgmSource();
        }

        public DataTable Report_SumUpPaymentFT(string dateFrom, string dateTo, string bgm_source_seq)
        {
           DateTime? ddateFrom = common.ConvertNullDateTime(dateFrom);
           DateTime? ddateTo = common.ConvertNullDateTime(dateTo);
           return dal.Report_SumUpPaymentFT(ddateFrom, ddateTo, bgm_source_seq);
        }

        public IList<M_FIM_Payments> GetNotRealPayment(string bgm_source_seq, string work_area_seq, string bgm_year, string method_seq)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nwork_area_seq = common.ConvertNullInt(work_area_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            Nullable<int> nmethod_seq = common.ConvertNullInt(method_seq);
            return dal.GetNotRealPayment(nbgm_source_seq, nwork_area_seq, nbgm_year, nmethod_seq);
        }

        public IList<M_FIM_Payments> GetAllRealPayment(string bgm_source_seq, string work_area_seq, string bgm_year, string method_seq)
        {
            int? nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            int? nwork_area_seq = common.ConvertNullInt(work_area_seq);
            int? nbgm_year = common.ConvertNullInt(bgm_year);
            int? nmethod_seq = common.ConvertNullInt(method_seq);
            return dal.GetAllRealPayment(nbgm_source_seq, nwork_area_seq, nbgm_year, nmethod_seq);
        }

        public IList<M_FIM_Payments> GetRealPaid(string pip_ref_no)
        {
            return dal.GetRealPaid(pip_ref_no);
        }

        public M_FIM_PaymentRecordPrints GetNextDocNoPND(string doc_type) {
                       
            return dal.GetNextDocNoPND(doc_type);
        
        }

        public M_FIM_PaymentRecordPrints GetPNDPrintInfo(int ref_id, string doc_type) {
            return dal.GetPNDPrintInfo(ref_id, doc_type);
        }

        public string InsertPNDPrint(M_FIM_PaymentRecordPrints info)
        {
            try
            {
                return dal.InsertPNDPrint(info);
            }
            catch
            {
                throw;
            }
        }

        public IList<M_FIM_Payments> GetReportPND(string strPaySeq)
        {
            return dal.GetReportPND(strPaySeq);
        }
    }
}
